#include <gtest/gtest.h>

#include <iostream>
#include <vector>

#include "elisa/elisa_variable.h"
#include "elisa/elisa_interval.h"

using namespace std;
using namespace elisa;

TEST(SearchTree, Init)
{
	SearchTree tree;

	ASSERT_FALSE(tree.isEmpty());
	ASSERT_TRUE(tree.getHeap()->isEmpty());
	ASSERT_EQ(tree.getRoot(), tree.getCurrent());
}

TEST(SearchTree, Allocate)
{
	SearchTree tree;

	long adr = tree.allocate<int>();
	tree.setDomain<int>(adr, 4);
	ASSERT_EQ(4, *(tree.domain<int>(adr)));
}

TEST(SearchTree, Allocate1)
{
	SearchTree tree;

	long adr = tree.allocate<vector<int> >();
	long adr1 = tree.allocate<vector<int> >();
	vector<int> v;
	v.push_back(123);
	v.push_back(456);
	tree.setDomain<vector<int> >(adr, v);
	vector<int> v1;
	v1.push_back(7);
	v1.push_back(8);
	v1.push_back(9);
	v1.push_back(10);
	v1.push_back(11);
	v1.push_back(12);
	tree.setDomain<vector<int> >(adr1, v1);
	vector<int> *pv = tree.domain<vector<int> >(adr);
	ASSERT_TRUE(v == *pv);
}

TEST(SearchTree, Reduce)
{
	SearchTree tree;

	long adr = tree.allocate<Interval>();
	tree.setDomain<Interval>(adr, Interval(4));
	ASSERT_EQ(Interval(4), *(tree.domain<Interval>(adr)));

	tree.reduce(adr, Interval(2));
	ASSERT_EQ(Interval(2), *(tree.domain<Interval>(adr)));

	tree.getCurrent()->goBack();
	ASSERT_EQ(Interval(4), *(tree.domain<Interval>(adr)));
		
	tree.getCurrent()->goChild(tree.getCurrent()->getChildren()[0]);
	ASSERT_EQ(Interval(2), *(tree.domain<Interval>(adr)));
}

/*
TEST(SearchTree, Split)
{
	SearchTree tree;

	long adr = tree.allocate<Interval>();
	tree.setDomain<Interval>(adr, Interval(4));

	tree.splitBox<Interval>(adr, Interval(1), Interval(2));
	ASSERT_EQ(Interval(4), *(tree.domain<Interval>(adr)));

	tree.getCurrent()->goChild(tree.getCurrent()->getChildren()[0]);
	ASSERT_EQ(Interval(1), *(tree.domain<Interval>(adr)));
		
	tree.getCurrent()->goBack();
	ASSERT_EQ(Interval(4), *(tree.domain<Interval>(adr)));

	tree.getCurrent()->goChild(tree.getCurrent()->getChildren()[1]);
	ASSERT_EQ(Interval(2), *(tree.domain<Interval>(adr)));
}
*/
